<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>基础数据管理-项目信息新增</title>
    <script src="/scripts/boot.js"></script>
    <link href="/scripts/daterangepicker/js/daterangepicker.min.css" rel="stylesheet" type="text/css" />
    <script src="/scripts/daterangepicker/js/moment.js" type="text/javascript"></script>
    <script src="/scripts/daterangepicker/js/jquery.daterangepicker.min.js" type="text/javascript"></script>
    <script src="/scripts/daterangepicker/ux.daterangepicker.js" type="text/javascript"></script>
    <link href="/scripts/daterangepicker/css/skin.css" rel="stylesheet" type="text/css" />
    <!--//上传插件-->
    <link href="/scripts/webuploader/css/webuploader.css" rel="stylesheet" type="text/css" />
    <link href="/scripts/webuploader/css/style.css" rel="stylesheet" type="text/css" />
    <script src="/scripts/webuploader/js/webuploader.js"></script>
    <script src="/scripts/webuploader/js/upload.js"></script>
    <style>
        html body .searchbox .mini-buttonedit-icon
        {
            /*background:url(static/scripts/daterangepicker/search.gif) no-repeat 50% 50%;*/
        }
    </style>
</head>
<body class="bg-white">
<div id="viewForm">
    <div class="title-info mb-20"><span>计划信息</span></div>
    <table class="table-bg" border="0" cellpadding="1" cellspacing="1" style="width:100%;table-layout:fixed;">
        <colgroup>
            <col width="135px"></col>
            <col width="50%"></col>
            <col width="135px"></col>
            <col width="50%"></col>
        </colgroup>
        <tr>
            <td class="text-titlebg">
                计划名称
            </td>
            <td>
                <input type="text" name="planName" class="mini-textbox w250" enabled="false" required="true" errorMode="none" onvalidation="onNullValidation" requiredErrorText="请输入"　vtype="maxLength:48"/>
            </td>
            <td class="text-titlebg">计划类型</td>
            <td>
                <input type="text" name="planTypeName" class="mini-textbox w250" enabled="false" required="true" errorMode="none" onvalidation="onNullValidation" requiredErrorText="请输入"　vtype="maxLength:48"/>
            </td>

        </tr>
        <tr>
        	<td class="text-titlebg">
                计划节点名称
            </td>
            <td>
                <input type="text" name="nodeName" class="mini-textbox w250" enabled="false" required="true" errorMode="none" onvalidation="onNullValidation" requiredErrorText="请输入"　vtype="maxLength:48"/>
            </td>
            <td class="text-titlebg">
                计划起止日期
            </td>
            <td>
                <input id="date-range1" class="uc-daterangepicker searchbox w250" enabled="false"/>
            </td>
        </tr>
        <tr>
	        <td class="text-titlebg">是否完成</td>
	        <td >
	            <input name="isComplete" id="isComplete" class="mini-radiobuttonlist w250" onvaluechanged="view.isCompleteValue" value="0" data="[{id: 0, text: '未完成'}, {id: 1, text: '完成'}]"/>
	        </td>
            <td class="text-titlebg"><span class="color-red">*</span>当前进度</td>
            <td>
           		<!-- <input id="rate" name="rate" class="mini-spinner w250"  minValue="1" maxValue="100" />% -->
           		<input id = "rate" name="rate" class="mini-combobox w250" required="true" 
           		data="[{ id: '10', text: '10' }, { id: '20', text: '20'}, { id: '30', text: '30'}, { id: '40', text: '40'},
           		{ id: '50', text: '50' }, { id: '60', text: '60'}, { id: '70', text: '70'}, { id: '80', text: '80'},
           		{ id: '90', text: '90' }]"  value="" errorMode="none" onvalidation="onChoseValidation"/>%
            </td>
            
        </tr>
        <tr class="noBox">
        	<td class="text-titlebg">
                预计结束时间
            </td>
            <td colspan="3">
                <input id="date-range" name="expectDate"  class="mini-datepicker searchbox w250" ondrawdate="view.onDrawDate" />
            </td>
        </tr>
        <tr class="yesBox">
            <td class="text-titlebg">
                <span class="color-red">*</span>实际结束日期
            </td>
            <td colspan="3">
                <input type="text" id="overDate"  name="overDate" class="mini-datepicker w250" allowInput="false" required="true" errorMode="none" ondrawdate="view.onDrawDate2"/>
            </td>
        </tr>
        <tr>
            <td class="text-titlebg noEmpty">说明</td>
            <td colspan="3" class="wp">
                <textarea name="completeIns" class="mini-textarea wtextarea" emptyText=""></textarea>
                
			    <input name="planNodeId" id="planNodeId" class="mini-hidden"/>
            </td>
        </tr>
    </table>
     <div class="yesDataBox">
         <div class="title-info"><span>详细信息</span>
             <div class="position-rel">
                 <div class="position-abs">
                     <a onclick="view.addRow()" class="newly">新增</a>
                     <a class="delAll" onclick="view.removeRow()">删除</a>
                 </div>
             </div>
         </div>

         <div id="datagrid1" class="mini-datagrid" style="width:100%;height:280px; margin-top: 35px;" idField="id" url="/monthlyPlanExecution/fruitArchivesDetailedListByPage"
              allowResize="true" pageSize="20" allowCellEdit="true" allowCellSelect="true" multiSelect="true"  editNextOnEnterKey="true"  editNextRowCell="true">
             <div property="columns">
                 <div type="checkcolumn" allowResize="false" width="15"></div>
                 <div type="indexcolumn" allowResize="false" width="15">编号</div>
                 <div   field="id" name="id" hidden="true"  headerAlign="center" allowSort="true" allowResize="false">
                     <input property="editor"   class="mini-hidden" style="width:100%;" minWidth="100" />
                 </div>
                 <div field="achievementName" name="achievementName" headerAlign="center" allowSort="true" width="80" allowResize="false">成果名称
                     <input property="editor" class="mini-textbox" style="width:100%;" minWidth="200" />
                 </div>
                 <div field="achievementNature" displayField="achievementNature_value" name="achievementNature"  width="60" headerAlign="center" allowSort="true" allowResize="false">成果性质
                     <!--<input property="editor" class="mini-combobox" url="/dictionary/listValues?name=achievementNature"  textField="value" valueField="id" />-->
                     <input property="editor" class="mini-combobox" url="/dictionary/listValues?name=achievementNature"  textField="value" valueField="id" />
                 </div>
                 <div field="achievementTime"  name="achievementTime" renderer="view.ondayRenderer" headerAlign="center"  width="40" allowSort="true" allowResize="false">成果取得时间
                     <input property="editor" class="mini-datepicker"  minValue="0" maxValue="200" value="25" style="width:100%;"/>
                 </div>
                 <div field="patternManifestation" displayField="patternManifestation_value" headerAlign="center" name="patternManifestation" width="50" allowSort="true" allowResize="false">表现形式
                     <input property="editor" class="mini-combobox"  url="/dictionary/listValues?name=patternManifestation"  textField="value" valueField="id" />
                 </div>
                 <div field="storagePlace"  name="storagePlace" width="50" allowSort="true" allowResize="false">原始资料存放位置
                     <input property="editor" class="mini-textbox"  minValue="0" maxValue="200" value="25" style="width:100%;"/>
                 </div>
                 <div  field="file_url" name="file_url" hidden="true"  headerAlign="center" allowSort="true" allowResize="false">
                     <input property="editor" class="mini-hidden" style="width:100%;" minWidth="200" />
                 </div>
                 <div field="file_name" name="file_name" renderer="view.getFile"  headerAlign="center" allowSort="true" allowResize="false">已上传文件
                     <input property="editor" class="mini-hidden" style="width:100%;" minWidth="200" />
                 </div>
                 <div field="" name="action" renderer="view.onActionRenderer" headerAlign="center" align="center"  width="45" allowSort="true"allowResize="false" >操作

                 </div>

             </div>
         </div>
     </div>
    
    <div class="attachment-box">
        <div class="attachment-title">
            <div class="attachment-text">
                <span class="blue-dot"></span>附件
            </div>
        </div>
        <div class="attachment-content">
            <div id="file_ll" class="webuploader-container">
                <a class="up-botton" onclick="view.uploadSup('NO')"><span class="add-bg"></span>上传</a>
                <span id="span"></span>
            </div>
            <input name="fileUrl" id="file_url" class="mini-hidden"  />
            <input name="fileName" id="file_name" class="mini-hidden" />
        </div>
        <!--<div class="attachment-content">-->
            <!--<a class="update-button" onclick="openW()"></a>-->
            <!--<input name="fileUrl" id="file_url" class="mini-hidden"  />-->
            <!--<input name="fileName" id="file_name" class="mini-hidden" />-->
            <!--<div id="span"></div>-->
            <!--<div id="spanTaskBook1" class="updata-file"></div> &ndash;&gt;-->
            <!--<div id="uploader" class="webuploader-container"></div>-->
            <!--<input name="fileUrl" id="file_url" class="mini-hidden"  />-->
            <!--<input name="fileName" id="file_name" class="mini-hidden" />-->
        <!--</div>-->
    </div>
    <div class="mini-fit"></div>
    <div class="chose-toolbar">
        <a class="chose-button" onclick="CloseWindow('close')">取消</a>
        <a class="chose-button save-button" onclick="view.save()">保存</a>
    </div>
</div>
<script src="/scripts/res/js/common.js"></script>
<script type="text/javascript">
    top["win"]=window;
    var post_flag,form,state,datas,i ,idsss;
    //用于存储附件名
    var newData=[],noText=" ";
    var json;
    var isComplete=0;
    var view = {
        init: function () {
            common.areaItem.init({
                idName:'#areaItem',
                isItem: true
            });
            post_flag = false; //设置一个对象来控制是否进入AJAX过程
            mini.parse();
            form = new mini.Form("#viewForm");
            grid = mini.get("datagrid1");
            
            grid.hideColumn("id");//隐藏列
            grid.hideColumn("file_url");//隐藏列
            grid.on("celleditenter", function(e) {
                var index = grid.indexOf(e.record);
                if (index == grid.getData().length - 1) {
                    noText="";
                    var row = {};
                    grid.addRow(row);
                }
            });
            grid.on("rowclick",function (e) {
                noText =$('#span_id'+e.row._id).html();
            });
            grid.on("beforeload", function(e) {
                if (grid.getChanges().length > 0) {
                    if (confirm("有增删改的数据未保存，是否取消本次操作？")) {
                        e.cancel = true;
                    }
                }
            });
        },
        isCompleteValue:function(e){
            isComplete=e.value;
            $(".state-complete").remove();
            if(e.value==0){
                $(".yesBox").hide();
                $(".noBox").show();
                $(".attachment-box").show();
                $(".yesDataBox").hide();
                $(".save-button").attr("onclick","view.save()");
                $(".save-button").text("保存");
                mini.get("rate").setValue("10");
                mini.get("rate").setReadOnly(false);
            }else{
                $(".noBox").hide();
                $(".yesBox").show();
                $(".attachment-box").hide();
                $(".yesDataBox").show();
                mini.get("rate").setValue("100");
                $(".save-button").attr("onclick","view.saveFruitArchives()");
                $(".save-button").text("提交审批");
                mini.get("rate").setValue("100");
                mini.get("rate").setReadOnly(true);
            }
        },
        //格式化日期
        ondayRenderer: function(e) {
            if (e.value) {
                var value = new Date(e.value);
                if (value) {
                    return mini.formatDate(value, 'yyyy-MM-dd')
                }
            }else{
                return "";
            }
        },
        //添加行
        addRow: function() {
            var newRow = {
                name : "New Row"
            };
            noText="";
            grid.addRow(newRow, 0);

            grid.beginEditCell(newRow, "LoginName");
        },
        //移除行
        removeRow: function() {
            var rows = grid.getSelecteds();

            if (rows.length > 0) {
                var ids = [];
                for (var i = 0, l = rows.length; i < l; i++) {
                    var r = rows[i];
                    if(r.id){
                        ids.push(r.id);
                    }
                }

                idsss = ids.join(',');

            } else {
                alert("请选中一条记录");
            }
            if (rows.length > 0) {
                grid.removeRows(rows, true);
            }

        },//设置信息
        onActionRenderer: function(e){
            // var s ='<a class="update-button" onclick="view.aaaa()"></a>';
            var  s='<a class="up-botton" onclick="view.uploadSup(\'yes\','+e.row._uid+')"><span class="add-bg"></span>上传</a>';
            return s;
        },
        //点击上传按钮
        aaaa: function(){
           $('.webuploader-element-invisible').trigger('click');
        },
        getFile: function(e){
           var list = e.row.listFile;
           console.log(noText)
           var v="<div><sapn id='span_id"+e.row._id+"'>"+noText+"</span></div>";
           if(list){
               for(var i=0;i<list.length;i++){
                   var file = list[i];
                   var fileName = file.file_name;
                   var fileUrl = file.file_url;
                   var fileid =	file.id;
                   var a= "<div id='"+fileid+"' class='file-box'>"+
                       "<a class='file-name' href='javascript:void(0)' onclick=\"view.downFile('" +fileUrl+"','"+fileName+"')\">"+fileName+"</a>"+
                       "<span class='img-wh' onclick=\"view.delFile('"+fileUrl+"')\"></span>"+
                       "</div><br/>";
                   v+=a;
               }
           }
           return v;
        },
//    数据展示
        SetData: function (data) {
            data = mini.clone(data);
            state = data.state;
            
            
            $.ajax({
                url:"/monthlyPlanExecution/info?id=" + data.id,
                type: "post",
                success: function (text) {
                	var obj = JSON.parse(text);
                    //跨页面传递的数据对象，克隆后才可以安全使用
                    datas = mini.decode(obj.body[0]);   //反序列化成对象
                    form.setData(datas);             //设置多个控件数据
                    mini.get("date-range1").setValue(datas.beginDate +" ~ " +datas.endDate);
                    mini.get("isComplete").setValue("0");
                    mini.get("planNodeId").setValue(data.id);
                    $(".yesBox").hide();
                    $(".noBox").show();
                    $(".attachment-box").show();
                    $(".yesDataBox").hide();
                }
            });

        },
        uploadSup: function(obj,uid){
           var isComplete= mini.get("isComplete").getValue();
            mini.open({
                // url: "/upload/index.html?isComplete="+isComplete,
                url: "/upload/index.html",
                title: "上传附件", width: 1100, height: 500,
                onload: function () {
                    var data = {"state": obj,'uid':(uid?uid:"")};
                    var iframe = this.getIFrameEl();
                    iframe.contentWindow.uploadFile.setDate(data);
                },
                ondestroy: function (action) {
                    // CloseWindow('ok');
                }
            });
        },
        upload: function(){
        	//附件上传
			view.uploadFilesThis({
				config : {
					// accept : 'image/png,image/jpg,image/jpeg,image/gif,.xls,.doc,.txt,.pdf',
					accept : '*.*',
					multiple : true,
                    sync:true,//是否展示数据
				},
				success : function(data){
                    //获取附件
                    templeteFile =data;
				}
			});
        },
        //	获取文件名称
        getFileName :function(path){
            var pos1 = path.lastIndexOf('/');
            var pos2 = path.lastIndexOf('\\');
            var pos = Math.max(pos1, pos2);
            if (pos < 0) {
                return path;
            }
            else {
                return path.substring(pos + 1);
            }
        },
        //保存1
        saveFruitArchives: function(){
           var ddddd=newData;
           form.validate();
           if (form.isValid() == false){
        	   mini.alert("实际结束时间不能为空");
        	   return; 
           } 
           var data1 = form.getData();      //获取表单多个控件的数据
           data1['id']=data1.planNodeId;
           delete data1["planNodeId"];
           data1['completeDate']=data1.overDate;
           delete data1["overDate"];
           data1['remark']=data1.completeIns;
           
           delete data1["completeIns"];
           var infoss = grid.data;
           for(var m=0;m<ddddd.length;m++){

               var fileuu = ddddd[m];
               var u_id = fileuu.split(":");

               for(var n=0;n<infoss.length;n++){
                   var filess = infoss[n];
                   var _id = filess._id;
                   if(u_id[0]==_id){
                       infoss[n].file_name=u_id[1];
                       break;
                   }
               }

           }
           var arr = [];
           if(infoss.length>0){

	           for(f in infoss){
	               var info = infoss[f];
	               var achievementName =  info.achievementName;
	               if(achievementName){
	                   if(info.achievementName == undefined){
	                	   mini.alert("成果名称不能为空");
	                	   return; 
	                   }
	                   if(info.achievementNature == undefined){
	                	   mini.alert("成果性质不能为空");
	                	   return; 
	                   }
	                   if(info.patternManifestation == undefined){
	                	   mini.alert("表现形式不能为空");
	                	   return; 
	                	   
	                   }
	                   var achievementName =  info.achievementName;
	                   var achievementNature =  info.achievementNature;
	                   var achievementTime  =  info.achievementTime;
	                   var patternManifestation =  info.patternManifestation;
	                   var storagePlace =  info.storagePlace;
	                   var fileUrl =  info.file_url;
	                   var fileName =  info.file_name;
	                   var id =  info.id;
	
	                   var m={
	                       "achievementName":achievementName,
	                       "achievementNatureId":achievementNature,
	                       "achievementTime":achievementTime,
	                       "fileUrl":fileUrl,
	                       "fileName":fileName,
	                       "patternManifestationId":patternManifestation,
	                       "storagePlace":storagePlace
	                   };
	                   if(id){
	                       m.id=id;
	                   }
	                   arr.push(m);
	               }
	           }
           }
           var d = {};
           d.detailinfos=arr;
           d.planNode=data1;
           var info = JSON.stringify(d);

           $.ajax({
               type : "post",
               url : "/monthlyPlanExecution/saveKeyFruitArchives",
               data : {"data":info},
               success : function(msg) {

               	if(msg.state){
                       common.loading("加载中");
               		view.audit(msg.message)
               	}
               }
           });
           if(idsss){
               view.delAll(idsss);
           }
        },
        //保存2
        save: function () {
            form.validate();
            if (form.isValid() == false) return;
            if (post_flag) return;
            var data = form.getData();//获取表单多个控件的数据
            if(data.rate==0){
                common.prompt("请填写正确的进度");
                return
            }
            if(data.expectDate==""){
                delete data["expectDate"];
            }
            if(data.overDate==""){
                delete data["overDate"];
            }
            
            
            data['currentProgress']=data.rate;
            delete data["rate"];
            data['planNode.id']=data.planNodeId;
            delete data["planNodeId"];
            
            post_flag = true;
            $.ajax({
                url: ("/planFeedBack/save"),
                type: "post",
                data: data,
                success: function (msg) {
                    post_flag = false;
                    common.unmask();
                    CloseWindow("ok");
                },
                error: function (errorMsg) {
                    post_flag = false;
                    common.unmask();
                }
            });
        },
        //审核
        audit:function (id) {
           $.ajax({
				type : "post",
				url : "/loggerService/startPost",
				data : {"id":id,"formSign":"CDJHGLJHZXCGTB_01","workFlowId":"CDJHGLJHZXCGTBSP","jumpUrl":"/program/monthlyPlan/workflow.html?id="+id,"url":"/act/taskApi/start","exampleEntity":"planNode"},
				success : function(msg) {
					if(msg.message==="ok"){
	                    CloseWindow("ok");
					}
				}
			}); 
        } ,
         setFile_url: function(url,num){
        	 if(isComplete==1){
        		 var row = grid.getSelected ();
                 var old_url= row.file_url;

                 if(!old_url){
                     grid.updateRow(row,{file_url:url})
                 }else{
                     if(old_url!=""){
                         old_url=old_url+";  "
                     }
                     var value = old_url+url;

                     grid.updateRow(row,{file_url:value})
                 }
        	 }else{
        		 var old_url=mini.get('file_url').getValue();
                 if(old_url!=""){
                     old_url=old_url+";"
                 }
                 var value = old_url+url;
                 // grid.updateRow(row,{file_url:value});
                 mini.get('file_url').setValue(old_url+url);
        	 }
         },
         setFile_name: function(name, num) {
        	 if(isComplete==1){
	            var row = grid.getSelected();
	            var rowId = row._id;
	            var leth = newData.length;
	            if(leth>0){
	                var d ;
	                var m=0;
	                for(var i=0;i<newData.length;i++){
	
	                    d = newData[i];
	                    var aa = d.split(":");
	                    var aaa = aa[0];
	                    if(aaa==rowId){
	                        d=d+";  "+name;
	                        newData[i] = d;
	
	                        var bb = d.split(":");
	                        var value = bb[1];
	                        $("#span_id"+row._id).append(value);
	                        break;
	                    }else{
	                        m++;
	                    }
	                }
	                if(m==newData.length){
	                    var a = rowId+":"+name;
	                    newData.push(a);
	                    $("#span_id"+row._id).append(name);
	                }
	            }else{
	                var a = rowId+":"+name;
	                newData.push(a);
	                $("#span_id"+row._id).append(name);
	            }
        	 }else{
	            var old_name=mini.get('file_name').getValue();
	            if(old_name!=""){
	                old_name=old_name+";"
	            }
                 var value = old_name+name;
                 mini.get('file_name').setValue(old_name+name);
	
	            var span = $("#span");
	            span.append(name+"  ;");
        	 }
         },
        delAll:function(idsss){
           $.ajax({
               url: "/settlement/plan/info/datum/delAll?id="+idsss,
               success: function (text) {
                   grid.reload();
               },
               error: function () {
               }
           });

        },
         downFile: function(url, name) {
            window.location.href = "/ftp/downFile?path=" + url
                + "&fileName=" + name;
         },
         onDrawDate: function (e) {
             var date = e.date;
             if (date.getTime() <= new Date().getTime()) {
                 e.allowSelect = false;
             }
         },
         onDrawDate2: function (e) {
             var date = e.date;
             if (date.getTime() >= new Date().getTime()) {
                 e.allowSelect = false;
             }
         }
    };
    view.init();
</script>
</body>
</html>